package util.components;


import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

/*Editor basico de texto en html.
 * guardar en @Column(type="text") 
 * en reporte poner propiedad de campo mark = "html"
 * y para que se vea igual Calibri 14
 * No considera sangrias
 * 
 */


/**
 *
 * @author raul
 */
public class EditorHTML extends javax.swing.JPanel {

    
    /**
     * Creates new form EditorHTML
     */
    public EditorHTML() {
        initComponents();
        setearFuente();
        
    }

    private void setearFuente() {
        HTMLDocument doc = (HTMLDocument) editorTxt.getDocument();
        SimpleAttributeSet sas = new SimpleAttributeSet();
        StyleConstants.setFontFamily(sas, "Calibri");
        StyleConstants.setFontSize(sas, 14);
        doc.setParagraphAttributes(0, doc.getLength(), sas, false);
    }
    
    public String getText(){
        return editorTxt.getText();
    }
    
    public void setText(String text) {
        editorTxt.setText(text);
        setearFuente();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form EditorHTML.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        bold = new javax.swing.JButton();
        italic = new javax.swing.JButton();
        underline = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jScrollPane1 = new javax.swing.JScrollPane();
        editorTxt = new javax.swing.JTextPane();

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setOpaque(false);

        bold.setAction(new HTMLEditorKit.BoldAction());
        bold.setText("");
        bold.setIcon(new javax.swing.ImageIcon(getClass().getResource("/util/components/bold.png"))); // NOI18N
        bold.setFocusable(false);
        bold.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bold.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(bold);

        italic.setAction(new HTMLEditorKit.ItalicAction());
        italic.setText("");
        italic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/util/components/italic.png"))); // NOI18N
        italic.setFocusable(false);
        italic.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        italic.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(italic);

        underline.setAction(new HTMLEditorKit.UnderlineAction());
        underline.setText("");
        underline.setIcon(new javax.swing.ImageIcon(getClass().getResource("/util/components/underline.png"))); // NOI18N
        underline.setFocusable(false);
        underline.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        underline.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(underline);
        jToolBar1.add(jSeparator1);

        editorTxt.setContentType("text/html");
        jScrollPane1.setViewportView(editorTxt);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bold;
    private javax.swing.JTextPane editorTxt;
    private javax.swing.JButton italic;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton underline;
    // End of variables declaration//GEN-END:variables

    
}
